<%@ page import="com.hc.commodity.dao.impl.DeptDaoImpl" %>
<%@ page import="com.hc.commodity.pojo.Dept" %>
<%@ page import="java.util.List" %>
<%@ page import="com.hc.commodity.pojo.Emp" %>
<%@ page import="com.hc.commodity.dao.impl.EmpDaoImpl" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/4/9
  Time: 19:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>员工新增</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
</head>
<body>

<%
    //1. 查找所有部门
    List<Dept> deptList = new DeptDaoImpl().findAll();
    pageContext.setAttribute("deptList",deptList);

    request.setCharacterEncoding("utf-8");
    String ename = request.getParameter("ename");
    if (ename != null){
        Emp emp = new Emp();
        emp.setEname(ename);
        emp.setJob(request.getParameter("job"));
        emp.setMgr(Integer.parseInt(request.getParameter("mgr")));
        emp.setSal(Double.parseDouble(request.getParameter("sal")));
        emp.setDeptno(Integer.parseInt(request.getParameter("deptno")));
        new EmpDaoImpl().addEmp(emp);
        request.getRequestDispatcher("empManage.jsp").forward(request,response);
    }
%>
<div class="container">
    <ul class="breadcrumb">
        <li><a href="#">员工管理系统</a></li>
        <li><a href="empManage.jsp" target="mainFrame">员工管理</a></li>
        <li><a href="#">新增员工</a></li>
    </ul>
    <form class="form-horizontal" action="empInsert.jsp" method="post">
        <div class="form-group">
            <label for="ename" class="col-md-2 control-label col-md-offset-2">姓名</label>
            <div class="col-md-3">
                <input type="test" class="form-control" id="ename" placeholder="请输入员工姓名" name="ename">
            </div>
        </div>
        <div class="form-group">
            <label for="job" class="col-md-2 control-label col-md-offset-2">职位</label>
            <div class="col-md-3">
                <input type="test" class="form-control" id="job" placeholder="请输入员工职位" name="job">
            </div>
        </div>
        <div class="form-group">
            <label for="mgr" class="col-md-2 control-label col-md-offset-2">上司编号</label>
            <div class="col-md-3">
                <input type="test" class="form-control" id="mgr" placeholder="请输入上司编号" name="mgr">
            </div>
        </div>
        <div class="form-group">
            <label for="sal" class="col-md-2 control-label col-md-offset-2">工资</label>
            <div class="col-md-3">
                <input type="test" class="form-control" id="sal" placeholder="请输入上司编号" name="sal">
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label col-md-offset-2">部门</label>
            <div class="col-md-3">
                <select name="deptno">
                    <option value="">--- 请选择部门 ---</option>
                    <c:forEach items="${deptList}" var="dept">
                        <option value="${dept.deptno}">${dept.deptno}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="form-group">
            <input type="submit" value="确定" class="col-md-offset-5 btn btn-primary">
        </div>
    </form>
</div>
</body>
</html>
